package com.ruoyi.use.controller;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.use.vo.ExamUseVO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.use.domain.ExaminationUse;
import com.ruoyi.use.service.IExaminationUseService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 使用记录Controller
 * 
 * @author mqs
 * @date 2024-05-03
 */
@Controller
@RequestMapping("/use/use")
public class ExaminationUseController extends BaseController
{
    private String prefix = "use/use";

    @Autowired
    private IExaminationUseService examinationUseService;

    @RequiresPermissions("use:use:view")
    @GetMapping()
    public String use()
    {
        return prefix + "/use";
    }

    @RequiresPermissions("use:use:view")
    @GetMapping("/my")
    public String myExamUse()
    {
        return prefix + "/myExamUse";
    }

    /**
     * 查询使用记录列表
     */
    @RequiresPermissions("examUse:examUse:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ExamUseVO examUseVO)
    {
        startPage();
        List<ExamUseVO> list = examinationUseService.selectExaminationUseList(examUseVO);
        return getDataTable(list);
    }

    /**
     * 查询我的使用记录列表
     */
    @RequiresPermissions("examUse:examUse:view")
    @PostMapping("/mylist")
    @ResponseBody
    public TableDataInfo mylist(ExamUseVO examUseVO)
    {
        SysUser sysUser = ShiroUtils.getSysUser();
        examUseVO.setFounder(sysUser.getUserId().intValue());
        startPage();
        List<ExamUseVO> list = examinationUseService.selectExamUseList(examUseVO);
        return getDataTable(list);
    }
    /**
     * 导出使用记录列表
     */
    @RequiresPermissions("examUse:examUse:export")
    @Log(title = "使用记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ExamUseVO examUseVO)
    {
        List<ExamUseVO> list = examinationUseService.selectExaminationUseList(examUseVO);
        ExcelUtil<ExamUseVO> util = new ExcelUtil<ExamUseVO>(ExamUseVO.class);
        return util.exportExcel(list, "使用记录数据");
    }

    /**
     * 新增使用记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存使用记录
     */
    @RequiresPermissions("use:use:add")
    @Log(title = "使用记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ExaminationUse examinationUse)
    {
        return toAjax(examinationUseService.insertExaminationUse(examinationUse));
    }

    /**
     * 修改使用记录
     */
    @RequiresPermissions("examUse:examUse:view")
    @GetMapping("/view/{examId}")
    public String view(@PathVariable("examId") Long examId, ModelMap mmap)
    {
        ExamUseVO examUseVO = examinationUseService.selectExaminationUseByExamId(examId);
        mmap.put("examinationUse", examUseVO);
        return prefix + "/view";
    }

    /**
     * 修改保存使用记录
     */
    @RequiresPermissions("use:use:edit")
    @Log(title = "使用记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ExaminationUse examinationUse)
    {
        return toAjax(examinationUseService.updateExaminationUse(examinationUse));
    }

    /**
     * 删除使用记录
     */
    @RequiresPermissions("use:use:remove")
    @Log(title = "使用记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(examinationUseService.deleteExaminationUseByExamIds(ids));
    }
}
